package com.raymond.sgip.codec.encodeing;

import com.raymond.client.codec.encodeing.BaseEncoder;
import com.raymond.client.msg.BaseMessage;
import com.raymond.sgip.msg.AbstractSgipMessage;
import io.netty.buffer.ByteBuf;

/**
 * @author :  raymond
 * @version :  V1.0
 * @date :  2022-11-10 21:43
 */
public abstract class BaseSgipEncoder extends BaseEncoder {
    @Override
    public void encode(BaseMessage msg, ByteBuf out) throws Exception {
        byte[] body = encode0(msg);
        out.writeInt(body.length + 20);
        out.writeInt(msg.getCommandId());
        AbstractSgipMessage message = (AbstractSgipMessage) msg;
        out.writeInt(message.getGateId());
        out.writeInt(message.getTimeStamp());
        out.writeInt(msg.getSequenceId());
        out.writeBytes(body);
    }
}
